// import Vue from 'vue'
// import * as filter from './filter'

// Object.keys(filter).forEach(k => Vue.filter(k, filter[k]))

// Vue.prototype.$formatDate = Vue.filter('formatDate')
// Vue.prototype.$hidePhone = Vue.filter('hidePhone')
// import parseTime, formatTime and set to filter
import dayjs from 'dayjs'

export function dateFormat(value, format) {
  if (value) {
    return dayjs(value).format(format || 'YYYY-MM-DD HH:mm')
  } else {
    return value
  }
}

export function imgPath(value) {
  if (value) {
    return process.env.VUE_APP_FILE_SERVER_API+'/fms/api/show/' + value + '_0'
  } else {
    return ''
  }
}
export function imgPaths(value) {
  if (value) {
    return process.env.VUE_APP_FILE_SERVER_API + value
  } else {
    return ''
  }
}
export function filePath(value, type) {
  if (value) {
    return `/fms/api/show/${value}_${type || 0}`
  }
  return value
}

export function spliceStr(str, length = 8) {
  return str.length > length ? str.slice(0, length) + '...' : str
}

export function spliceFileName(fileName, length = 4) {
  const lastIndex = fileName.lastIndexOf('.')

  const str = fileName.slice(0, lastIndex - 1)
  const lastStr = fileName.slice(lastIndex - 1, fileName.length)

  return str.length > length ? str.slice(0, length) + '...' + lastStr : fileName
}

export function processInstanceStatus(status, isCancel) {
  if (isCancel === 1) return '已取消'

  if (status === 'IN_PROGRESS') return '进行中'

  if (status === 'END') return '已结束'

  return ''
}

export function timerZero(date) {
  return /\d{4}-\d{2}-\d{2}/.exec(date)
    ? /\d{4}-\d{2}-\d{2}/.exec(date)[0]
    : '无'
}


function padLeftZero(str) {
  return ('00' + str).substr(str.length)
}
/*
 * 隐藏用户手机号中间四位
 */
export function hidePhone(phone) {
  if(phone){
    return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
  }
  
}

